<template>
	<view class="income">
		<view class="mengban"></view>

		<view class="nav_bar">
			<uni-nav-bar color="#333" left-icon="left" title="收益" :border='false' :fixed="true"
				background-color="transparent" @clickLeft="$native.backAction()"></uni-nav-bar>
		</view>

		<view class="nav_box"></view>

		<view class="content">
			<view class="card flex_c">
				<view class="top flex_r_between">
					<view class="top_title">总额(元)</view>
					<view class="top_rich flex_center" @click="$util.toUrl('/pages/agreement/joincircle')">
						<u-icon name="question-circle" color="#999999" size="28rpx"></u-icon>
						<text>说明</text>
					</view>
				</view>
				<view class="bottom">
					{{ all_money }}
				</view>
			</view>

			<view class="list">
				<view class="header flex_r_between">
					<view class="header_title">明细</view>
					<view class="flex_center">
						<view class="header_time flex_center" @click="type_show = true">
							<view>{{
								type == 0 ? '全部'
								: type == 1 ? '入圈费'
								: type == 2 ? 'VIP'
								: type == 4 ? '商品'
								: type == 3 ? '活动'
								: type == 6 ? '付费视频'
								: type == 7 ? '直播'
								: ''
							}}</view>
							<u-icon name="arrow-down-fill" color="#999999" size="24rpx"></u-icon>
						</view>
						<view style="width: 16rpx;"></view>
						<view class="header_time flex_center" @click="time_show = true">
							<view>
								<uni-dateformat :date="time" format="yyyy.MM"></uni-dateformat>
							</view>
							<u-icon name="arrow-down-fill" color="#999999" size="24rpx"></u-icon>
						</view>
					</view>
				</view>
				<view class="list_content">
					<scroll-view scroll-y="true" @scrolltolower="onBottom">
						<view class="item flex_r_between" v-for="(item,index) in list" :key="index">
							<view class="left flex_center">
								<image :src="item.avatar" mode="aspectFill"></image>
								<view class="nickname">
									<text>{{ item.msg }}</text>
									<view>
										<uni-dateformat :date="item.create_time * 1000"
											format="yyyy.MM.dd hh:mm:ss"></uni-dateformat>
									</view>
								</view>
							</view>
							<view class="right">
								+{{ item.price }}
							</view>
						</view>
						<view class="loading flex_r_around" v-if="total > list.length">
							<u-loading-icon mode="semicircle" text=""></u-loading-icon>
						</view>

						<view class="loading flex_r_around" v-if="total == 0">
							<empty></empty>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>

		<u-datetime-picker :show="time_show" mode="year-month" :closeOnClickOverlay="true" @close="time_show = false"
			@cancel="time_show = false" v-model="time" :maxDate="now" @confirm="onDate">
		</u-datetime-picker>

		<u-picker :show="type_show" :columns="type_list" keyName="label" @close="type_show = false"
			@cancel="type_show = false" @confirm="onType"></u-picker>

	</view>
</template>

<script>
	import empty from '@/compentents/empty/empty.vue';
	export default {
		components: {
			empty
		},
		data() {
			return {
				time_show: false,

				time: '',

				now: 0,

				total: 1,
				page: 1,
				list: [],

				all_money: '0.00',

				circle_id: 0,

				type: 0,

				type_show: false,
				type_list: [
					[{
							label: '全部',
							type: 0
						},
						{
							label: '入圈费',
							type: 1
						},
						{
							label: 'VIP',
							type: 2
						},
						{
							label: '商品',
							type: 4
						},
						{
							label: '活动',
							type: 3
						},
						{
							label: '付费视频',
							type: 6
						},
						{
							label: '直播',
							type: 7
						},
					]
				],
			}
		},
		methods: {
			onDate(e) {
				this.time = e.value;
				this.page = 1;
				this.total = 1;
				this.list = [];
				this.getList();
				this.time_show = false;
			},

			onType(e) {
				this.type = e.value[0].type;
				this.page = 1;
				this.total = 1;
				this.list = [];
				this.getList();
				this.type_show = false;
			},

			getTimeText(time) {
				const date = new Date(time);
				const year = date.getFullYear();
				const month = date.getMonth() + 1; // 月份从0开始计算，需加1
				return `${year}-${month}`
			},

			getNow() {
				this.time = Number(new Date());
				this.now = Number(new Date());
			},

			onBottom() {
				if (this.total > this.list.length) {
					this.page++;
					this.getList();
				}
			},

			getList() {
				var time = this.getTimeText(this.time);
				this.$get('/circle.circle_member/getCirclePayLogList', {
					circle_id: this.circle_id,
					page: this.page,
					time: time,
					type: this.type
				}, true, (res) => {
					uni.stopPullDownRefresh();
				}).then(res => {
					uni.stopPullDownRefresh();
					this.all_money = res.data.all_money;
					this.total = res.data.list.total;
					this.list.push(...res.data.list.data);
				});
			},

		},

		onPullDownRefresh() {
			this.page = 1;
			this.total = 1;
			this.list = [];
			this.getList();
		},

		onLoad(option) {
			if (option.token) {
				uni.setStorageSync('token', option.token);
				uni.setStorageSync('cid', option.cid);
				uni.setStorageSync('terminal', option.terminal);
			}
			this.circle_id = option.circle_id || 0;
			this.getNow();
			this.getList();
		},
	}
</script>

<style lang="less" scoped>
	.income {
		width: 100vw;
		height: 100vh;
		padding: 10rpx 32rpx 40rpx;
	}

	.mengban {
		width: 100vw;
		height: 30vh;
		background: linear-gradient(270deg, #BFEAFF 0%, #FEFBFF 54%, #F1D8FA 100%);
		position: fixed;
		top: 0;
		left: 0;
		z-index: 1;
		// opacity: 0.6;
		filter: blur(60rpx);

	}

	.nav_bar {
		background: linear-gradient(270deg, #BFEAFF 0%, #FEFBFF 54%, #F1D8FA 100%);
	}

	.content {
		position: relative;
		z-index: 2;
		height: calc(100vh - 50rpx - 44px - var(--paging-head-top));

		.card {
			width: 686rpx;
			height: 208rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			margin-bottom: 20rpx;
			padding: 40rpx 32rpx;
			align-items: flex-start;
			justify-content: space-between;

			.top {
				width: 100%;

				.top_title {
					font-size: 28rpx;
					color: #000000;
					line-height: 40rpx;
				}

				.top_rich {
					text {
						font-size: 28rpx;
						color: #999999;
						line-height: 40rpx;
						margin-left: 6rpx;
					}
				}
			}

			.bottom {
				width: 100%;
				font-weight: 600;
				font-size: 64rpx;
				color: #000000;
			}
		}

		.list {
			width: 686rpx;
			background: #FFFFFF;
			height: calc(100vh - 50rpx - 44px - var(--paging-head-top) - 228rpx);
			border-radius: 24rpx;

			.header {
				height: 108rpx;
				border-bottom: 2rpx solid #F1F1F1;
				padding: 0 32rpx;

				.header_title {
					font-weight: 500;
					font-size: 32rpx;
					color: #131313;
				}

				.header_time {
					padding: 0 14rpx 0 16rpx;
					height: 48rpx;
					background: #F1F1F1;
					border-radius: 8rpx;

					view,
					text {
						font-weight: 500;
						font-size: 26rpx;
						color: #131313;
						margin-right: 8rpx;
					}
				}
			}

			.list_content {
				scroll-view {
					height: calc(100vh - 50rpx - 44px - var(--paging-head-top) - 228rpx - 108rpx);
				}

				.item {
					padding: 20rpx 32rpx;

					.left {
						image {
							margin-right: 16rpx;
							width: 96rpx;
							height: 96rpx;
							background: #D8D8D8;
							border-radius: 48rpx;
						}

						.nickname {
							text {
								font-weight: 500;
								font-size: 28rpx;
								color: #131313;
							}

							view {
								text {
									font-weight: normal;
									margin-top: 8rpx;
									font-size: 24rpx;
									color: #999999;
								}
							}
						}

					}

					.right {
						font-weight: 500;
						font-size: 28rpx;
						color: #131313;
					}
				}
			}

		}

	}
</style>